//
//  DPWalletFlowManager.swift
//  DoctorEPlus
//
//  Created by 王林波 on 2021/3/15.
//

import UIKit

class DPWalletFlowManager: NSObject {
    var currentTotal: Int = 0
    
    var markTime: String = ""
    
    func analyzeFlow(existArray: [DPWalletFlowModel], appendArray: [Any], completeHandler: ([DPWalletFlowModel], Int) -> Void) {
        
        var tempArray: [DPWalletFlowModel] = existArray
        
        if tempArray.count != 0 {
            markTime = tempArray.last!.month
        }else {
            self.currentTotal = 0
            markTime = ""
        }
        
        for dic in appendArray {
            let model = DPWalletFlowModel.init()
            model.month = BHJsonTool.decodeStringFromDic(dic: (dic as! [String: Any]), key: "yearMonth")
            model.inTotalAmount = BHJsonTool.decodeStringFromDic(dic: (dic as! [String: Any]), key: "monthIn")
            model.outTotalAmount = BHJsonTool.decodeStringFromDic(dic: (dic as! [String: Any]), key: "monthOut")
            
            let itemModel = DPWalletFlowItemModel.init()
            itemModel.parseDic(dic as! [String: Any])
            
            if markTime == model.month { // 时间相同，同一个月的数据
                let lastModel: DPWalletFlowModel = tempArray.last!
                lastModel.itemArray.append(itemModel)
            }else { // 时间不同，新的内容
                model.itemArray.append(itemModel)
                tempArray.append(model)
                markTime = model.month
            }
        }
        self.currentTotal += appendArray.count
        
        completeHandler(tempArray,self.currentTotal)
        
    }
    
    static func checkMoneyAvalid(_ inputMoney: String) -> (Bool,String) {
        let decimalInput = Decimal.init(string: inputMoney)!
        let decimalMax = Decimal.init(string: "100")!
        let result = decimalInput.isLess(than: decimalMax)
        if result == true {
            return (false,"提现金额不能小于100元")
        }else {
            return (true,"")
        }
    }

}
